<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
	<head>
		<base href="<%=basePath%>">
		<meta charset="utf-8" />
		<title></title>
		<meta name="description" content="overview & stats" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<link rel="stylesheet" href="static/css/bootstrap.min.css" />
		<link rel="stylesheet" href="static/css/bootstrap-responsive.min.css" />
		<link rel="stylesheet" href="static/css/font-awesome.min.css" />
		<!-- 下拉框 -->
		<link rel="stylesheet" href="static/css/chosen.css" />
		<link rel="stylesheet" href="static/css/ace.min.css" />
		<link rel="stylesheet" href="static/css/ace-responsive.min.css" />
		<link rel="stylesheet" href="static/css/ace-skins.min.css" />
		
		<script type="text/javascript" src="static/js/jquery-1.7.2.js"></script>
		<!--提示框-->
		<script type="text/javascript" src="static/js/jquery.tips.js"></script>
</head>
<body onload="verifyMessageType();">
	<div id="activity_part_id" style="display: none;">
			<!-- 检索  -->
			<form action="organfavoritemsgpush/pushOrganFavoriteMsg.do" method="post" name="commercialPublishActivityForm" id="commercialPublishActivityForm">
			<input type="hidden" name="organid" id="organid" value="${pageData.organid }"/>
			<input type="hidden" name="pushScope" id="pushScope" value="${pageData.pushScope }"/>
			<input type="hidden" name="message_type" id="message_type" value="${pageData.message_type }"/>
			<input type="hidden" name="message_type_act" id="message_type_act" value="3"/>
			<table id="table_report" class="table table-striped table-bordered table-hover">
				<thead>
					<tr>
						<th class="center">
							<label><input type="checkbox" id="zcheckbox" /><span class="lbl"></span></label>
						</th>
						<th>序号</th>
						<th>活动主题</th>
						<th><i class="icon-time hidden-phone"></i>开始日期</th>
						<th><i class="icon-time hidden-phone"></i>结束日期</th>
						<th>图片</th>
					</tr>
				</thead>
										
				<tbody>
				<!-- 开始循环 -->	
				<c:choose>
					<c:when test="${not empty varList}">
						<c:forEach items="${varList}" var="var" varStatus="vs">
							<tr>
								<td class='center' style="width: 30px;">
									<label><input type='checkbox' name='ids' value="${var.id }" id="choose_${var.id }"/><span class="lbl"></span></label>
								</td>
								<td class='center' style="width: 30px;">${vs.index+1}</td>
								<td>${var.info_title }</td>
								<td>${var.act_pub_time }</td>
								<td>${var.act_end_time }</td>
								<td>
									<c:if test="${var.act_img != '' && var.act_img != null }">
										<a href="<%=basePath%>${var.act_img}" target="_blank"><img src="<%=basePath%>${var.act_img}" width="50"/></a>
									</c:if>
								</td>
							</tr>
						</c:forEach>
					</c:when>
					<c:otherwise>
						<tr class="main_info">
							<td colspan="11" class="center" >没有相关数据</td>
						</tr>
					</c:otherwise>
				</c:choose>
				</tbody>
			</table>
			
		<div class="page-header position-relative">
			<table style="width:100%;">
				<tr>
					<td style="vertical-align:top;"><div class="pagination" style="float: right;padding-top: 0px;margin-top: 0px;">${page.pageStr}</div></td>
				</tr>
			</table>
		</div>
		</form>
	</div>
	
	<form action="<%=basePath%>/organfavoritemsgpush/save.do" name="Form" id="Form" method="post" enctype="multipart/form-data">
		<input type="hidden" name="pushScope" id="pushScope" value="${pageData.pushScope }"/>
		<input type="hidden" name="m_id" id="m_id" value="${pageData.m_id }"/>
		<input type="hidden" name="m_ids" id="m_ids" value="${pageData.m_ids }"/>
		<input type="hidden" name="act_ids" id="act_ids"/>
		<div id="centerOfMainFrame" style="margin-left: 10px;">
		<table style="width: 100%">
			<tr>
				<td>消息类别:
					<input name="message_class" type="radio" value="1" onclick="changeOrgMsgClass(this.value);" checked="checked"/><span class="lbl">文本消息</span>
					&nbsp;&nbsp;
					<input name="message_class" type="radio" value="2" onclick="changeOrgMsgClass(this.value);"/><span class="lbl">文本+图片消息</span>
				</td>
			</tr>
			<tr>
				<td>消息类型:
					<select name="message_type_current" id="message_type_current" title="消息类型" style="width:87%;" onchange="changeOrgMsgType(this.value);">
						<option value="1" selected>优惠消息</option>
						<option value="2">关怀消息</option>
						<option value="3">活动消息</option>
					</select>
				</td>
			</tr>
			<!-- <tr>
				<td>消息标题:
					<input type="text" style="width:85%;" name="message_title" id="message_title" placeholder="这里输入消息标题" title="消息标题"/>
				</td>
			</tr> -->
			<!-- <tr id="message_summary_current" class="info">
				<td>消息简介:
					<textarea title="最多可输入五十字" style="width:85%;height:120px" name="message_summary" id="message_summary" maxlength="50" onchange="this.value=this.value.substring(0, 50)" onkeydown="this.value=this.value.substring(0, 50)" onkeyup="this.value=this.value.substring(0, 50)"></textarea>
				</td>
			</tr> -->
			<tr class="info">
				<td>消息内容:
					<textarea title="最多可输入三百个字" style="width:85%;height:290px" name="message_content" id="message_content" maxlength="300" onchange="this.value=this.value.substring(0, 300)" onkeydown="this.value=this.value.substring(0, 300)" onkeyup="this.value=this.value.substring(0, 300)"></textarea>
				</td>
			</tr>
			<tr id="message_imageurl_current">
				<td>
					图片上传(建议上传800*400的图片效果最佳!): <input type="file" style="width:50%;" id="message_imageurl" name="message_imageurl"/>
				</td>
			</tr>
			<!-- <tr>
				<td>消息链接:
					<input type="text" style="width:85%;" name="message_link" id="message_link" placeholder="这里输入消息链接" title="消息链接"/>
				</td>
			</tr> -->
			<tr>
				<td style="text-align: center;">
					<a class="btn btn-mini btn-primary" onclick="makeAll();">提交</a>
					<a class="btn btn-mini btn-danger" onclick="top.Dialog.close();">取消</a>
				</td>
			</tr>
		</table>
		</div>
		<div id="centerOfMainFrame2" class="center" style="display:none"><br/><br/><br/><img src="static/images/jzx.gif" style="width: 50px;" /><br/><h4 class="lighter block green"></h4></div>
	</form>
</body>

<!-- 引入 -->
<script type="text/javascript">window.jQuery || document.write("<script src='static/js/jquery-1.9.1.min.js'>\x3C/script>");</script>
<script type="text/javascript" src="static/js/bootstrap.min.js"></script>
<script type="text/javascript" src="static/js/ace-elements.min.js"></script>
<script type="text/javascript" src="static/js/ace.min.js"></script>
<script type="text/javascript" src="static/js/chosen.jquery.min.js"></script><!-- 下拉框 -->
<script type="text/javascript" src="static/js/bootbox.min.js"></script><!-- 确认窗口 -->
<script type="text/javascript">
	$(top.hangge());
	
	$(function() {
		//单选框
		$(".chzn-select").chosen(); 
		$(".chzn-select-deselect").chosen({allow_single_deselect:true}); 
		
		//复选框
		$('table th input:checkbox').on('click' , function(){
			var that = this;
			$(this).closest('table').find('tr > td:first-child input:checkbox')
			.each(function(){
				this.checked = that.checked;
				$(this).closest('tr').toggleClass('selected');
			});
				
		});
	});
	
	//上传
	$('#message_imageurl').ace_file_input({
		no_file:'请选择图片 ...',
		btn_choose:'选择',
		btn_change:'更改',
		droppable:false,
		onchange:null,
		thumbnail:false //| true | large
		//whitelist:'gif|png|jpg|jpeg'
		//blacklist:'exe|php'
		//onchange:''
		//
	});
	
	function changeOrgMsgType(type) {
		if(type==3){
			$("#activity_part_id").css('display', ''); 
		}else{
			$("#activity_part_id").css('display', 'none'); 
		}
	}
	
	function changeOrgMsgClass(type) {
		//1:文本消息
		if(type==1){
			$("#message_imageurl_current").css('display', 'none'); 
		}else{
			//2:文本+图片
			$("#message_imageurl_current").css('display', ''); 
		}
	}
	
	function verifyMessageType() {
		var message_type = $("#message_type").val();
		//alert("verifyMessageType: " + message_type);
		if(message_type==3){
			$("#activity_part_id").css('display', ''); 
		}else{
			$("#activity_part_id").css('display', 'none'); 
		}
		
		//1:文本消息
		$("#message_imageurl_current").css('display', 'none'); 
	}
	
	//批量操作
	function makeAll(){
		if($("#message_content").val()==""){
			$("#message_content").tips({
				side:3,
	            msg:'请输入推送消息内容',
	            bg:'#AE81FF',
	            time:2
	        });
			
			$("#message_content").focus();
			return false;
		}
		
		var message_type_current = $("#message_type_current").val();
		//alert(message_type_current);
		if(message_type_current != 3){
			$("#Form").submit();
			$("#centerOfMainFrame").hide();
			$("#centerOfMainFrame2").show();
			return true;
		}else{
			bootbox.confirm("确定要提交选中的活动消息吗?", function(result) {
				if(result) {
					var str = '';
					var emstr = '';
					var phones = '';
					for(var i=0;i < document.getElementsByName('ids').length;i++){
						  if(document.getElementsByName('ids')[i].checked){
						  	if(str=='') str += document.getElementsByName('ids')[i].value;
						  	else str += ',' + document.getElementsByName('ids')[i].value;
						  	
						  	if(emstr=='') emstr += document.getElementsByName('ids')[i].id;
						  	else emstr += ';' + document.getElementsByName('ids')[i].id;
						  	
						  	if(phones=='') phones += document.getElementsByName('ids')[i].alt;
						  	else phones += ';' + document.getElementsByName('ids')[i].alt;
						  }
					}
					
					if(str==''){
						bootbox.dialog("您需要选择一个活动，请先选择一个活动!", 
							[
							  {
								"label" : "关闭",
								"class" : "btn-small btn-success",
								"callback": function() {
									//Example.show("great success");
									}
								}
							 ]
						);
						
						$("#zcheckbox").tips({
							side:3,
				            msg:'点这里选择当前页的活动',
				            bg:'#AE81FF',
				            time:8
				        });
						
						return;
					}else{
						$("#act_ids").val(str);
						$("#Form").submit();
						$("#centerOfMainFrame").hide();
						$("#centerOfMainFrame2").show();
						return true;
					}
				}
			});
		}
	}
	
	function textCounter(field, maxlimit) {
		if (field.value.length > maxlimit){
			field.value = field.value.substring(0, maxlimit);
		}else{
			document.upbook.remLen.value = maxlimit - field.value.length;
		}
	} 
</script>
</html>